#include "TrackLoader.h"
#include <fstream>
#include <iostream>

bool TrackLoader::load(const char * fileName, Track& t) {
	ifstream fin;
	fin.open(fileName);
	if (!fin) {
		std::cout << "Unable to load file " << fileName << "\n";
		return false;
	} else {
		t.clear();
		unsigned n;
		fin >> n;
		for (unsigned i = 0; i < n && !fin.eof(); i++) {
			int x;
			int y;
			fin >> x >> y;
			t.addPoint(x, y);
		}
		fin.close();
		return true;
	}
}

bool TrackLoader::load(const char * fileName, std::vector<Track>& tracks) {
	ifstream fin;
	fin.open(fileName);
	if (!fin) {
		std::cout << "Unable to load file " << fileName << "\n";
		return false;
	} else {
		tracks.clear();
		unsigned n;
		while(!fin.eof()) {
			fin >> n;
			tracks.push_back(Track());
			for (unsigned i = 0; i < n && !fin.eof(); i++) {
				int x;
				int y;
				fin >> x >> y;
				tracks.back().addPoint(x, y);
			}
		}
		fin.close();
		return true;
	}
}
